library(sf)
library(tidyverse)
library(leaflet)

cleaning NYC data and creating static plots in prepartion for shiny app

NYC Parks

parks_shp<-st_read("../data/Open_Space_Parks/geo_export_c3910f09-62a7-48c3-b859-47e26ec50538.shp")
## Reading layer `geo_export_c3910f09-62a7-48c3-b859-47e26ec50538' from data source `/Users/kristenakey/Desktop/Fall2020-Project2-group2/data/Open_Space_Parks/geo_export_c3910f09-62a7-48c3-b859-47e26ec50538.shp' using driver `ESRI Shapefile'
## Simple feature collection with 12491 features and 10 fields
## geometry type:  POLYGON
## dimension:      XY
## bbox:           xmin: -74.25537 ymin: 40.49613 xmax: -73.70182 ymax: 40.91138
## geographic CRS: WGS84(DD)
parks_shp %>%
  filter(!is.na(landuse),
         (landuse %in% c("Waterfront Facility",'Lot', 'Buildings/Institutions', 'Tracking Only',
                        '<Null>', 'Undeveloped', 'Cemetery', 'Retired N/A', 'Tracking')) == FALSE) %>%
  mutate(landuse = case_when(landuse=="Community Park" ~ "Park",
                             landuse=="Neighborhood Park" ~ "Park",
                             landuse=="Historic House Park" ~ "Park",
                             landuse=="Triangle/Plaza" ~ "Triangle/Plaza",
                             landuse=="Recreation Field/Courts" ~  "Recreation Field/Courts",
                             landuse=="Playground" ~ "Playground",
                             landuse=="Nature Area" ~ "Nature Area",
                             landuse=="Parkway" ~ "Parkway",
                             landuse=="LARGE PARK AREA" ~ "Park",
                             landuse=="Flagship Park" ~ "Park",
                             landuse=="EventArea" ~ "Park",
                             landuse=="Mall" ~ "Parkway",
                             landuse=="Garden" ~ "Parkway",
                             landuse=="Jointly Operated Playground" ~ "Playground",
                             landuse=="School Yard to Playground" ~ "Playground",
                             landuse=="Strip" ~ "Parkway"
                             )

         ) -> parks_shp


parks_shp %>%
  as.tibble() %>%
  dplyr::select(landuse) %>% distinct()
## # A tibble: 6 x 1
##   landuse                
##   <chr>                  
## 1 Park                   
## 2 Triangle/Plaza         
## 3 Parkway                
## 4 Recreation Field/Courts
## 5 Playground             
## 6 Nature Area
## save cleaned shapefile
# st_write(parks_shp, "../data/nyc_parks.shp")

Plot of parks

labels <- sprintf(
      "<strong>%s</strong>",
      parks_shp$park_name
    ) %>% lapply(htmltools::HTML)


leaflet()  %>% addTiles() %>% 
  setView(lng = -73.98928, lat = 40.75042,zoom=11) %>% 
  addPolygons(data=parks_shp,weight=5,col = 'green',
                label = labels,
                labelOptions = labelOptions(
                style = list("font-weight" = "normal", padding = "3px 8px"),
                textsize = "15px",
                direction = "auto")) %>%
  addProviderTiles("CartoDB.Positron", options = providerTileOptions(noWrap = TRUE))

NYC Covid-19 Open Streets

open_streets <- st_read("../data/Open_Streets_Locations/geo_export_4a00acf9-46e6-4357-a423-8d64d874a1b7.shp")
## Reading layer `geo_export_4a00acf9-46e6-4357-a423-8d64d874a1b7' from data source `/Users/kristenakey/Desktop/Fall2020-Project2-group2/data/Open_Streets_Locations/geo_export_4a00acf9-46e6-4357-a423-8d64d874a1b7.shp' using driver `ESRI Shapefile'
## Simple feature collection with 1829 features and 15 fields
## geometry type:  MULTILINESTRING
## dimension:      XY
## bbox:           xmin: -74.13064 ymin: 40.59231 xmax: -73.73858 ymax: 40.88736
## geographic CRS: WGS84(DD)
labels <- sprintf(
      "From Street: <strong>%s</strong><br/> To Street: <strong>%s</strong>",
      open_streets$from_stree, open_streets$to_street
    ) %>% lapply(htmltools::HTML)


leaflet()  %>% addTiles() %>% 
  setView(lng = -73.98928, lat = 40.75042, zoom=11) %>% 
  addPolygons(data=open_streets,weight=3,col = 'red',
                label = labels,
                labelOptions = labelOptions(
                style = list("font-weight" = "normal", padding = "3px 8px"),
                textsize = "15px",
                direction = "auto")) %>%
  addProviderTiles("CartoDB.Positron", options = providerTileOptions(noWrap = TRUE))
# can filter Open Streets 
leaflet() %>% addTiles() %>%
        addPolygons(data=open_streets[open_streets$type=="Open Streets: Restaurants",],weight=3,col = 'red') %>%
  addProviderTiles("CartoDB.Positron", options = providerTileOptions(noWrap = TRUE))

Bike lanes and CitiBike stations

bike_lanes <- st_read("../data/Bicycle_Routes/geo_export_21a36b1c-263a-41be-a2e0-091316a94ecc.shp")
## Reading layer `geo_export_21a36b1c-263a-41be-a2e0-091316a94ecc' from data source `/Users/kristenakey/Desktop/Fall2020-Project2-group2/data/Bicycle_Routes/geo_export_21a36b1c-263a-41be-a2e0-091316a94ecc.shp' using driver `ESRI Shapefile'
## Simple feature collection with 18730 features and 15 fields
## geometry type:  MULTILINESTRING
## dimension:      XY
## bbox:           xmin: -74.25185 ymin: 40.49804 xmax: -73.70242 ymax: 40.91142
## geographic CRS: WGS84(DD)
bike_lanes %>%
  as.tibble()
## # A tibble: 18,730 x 16
##    allclasses bikedir  boro comments facilitycl fromstreet ft_facilit instdate
##    <chr>      <chr>   <dbl> <chr>    <chr>      <chr>      <chr>      <chr>   
##  1 III        L           4 <NA>     III        WOODHAVEN… <NA>       2016-11…
##  2 II         L           3 <NA>     II         W 37 ST    <NA>       2005-08…
##  3 II         R           4 <NA>     II         SHORE PKW… Standard   2008-04…
##  4 I          2           3 Prospec… I          PROSPECT … Greenway   1980-07…
##  5 II         R           1 <NA>     II         CANAL ST   Standard   2008-04…
##  6 I          L           1 <NA>     I          W 96 ST    <NA>       2010-08…
##  7 III        L           3 <NA>     III        PROSPECT … <NA>       2008-10…
##  8 III        L           3 origina… III        PARK CIR   <NA>       2012-04…
##  9 III        L           1 <NA>     III        CHERRY ST  <NA>       2017-07…
## 10 I          R           3 <NA>     I          NAVY ST    Protected… 2009-11…
## # … with 18,720 more rows, and 8 more variables: lanecount <dbl>,
## #   moddate <chr>, onoffst <chr>, segmentid <dbl>, street <chr>,
## #   tf_facilit <chr>, tostreet <chr>, geometry <MULTILINESTRING [°]>

Citibike locations

library(jsonlite)

citibike<-fromJSON("https://gbfs.citibikenyc.com/gbfs/en/station_information.json")
citibike <- citibike$data$stations

leaflet(data = citibike) %>% addTiles() %>%
       addMarkers(lng=~lon,lat=~lat, label = ~legacy_id,
                  clusterOptions = markerClusterOptions()) %>%
        # addPolygons(data=bike_lanes,weight=3,col = 'red') %>%
  addProviderTiles("CartoDB.Positron", options = providerTileOptions(noWrap = TRUE))
citibike %>%
  unnest(rental_methods)
## # A tibble: 2,352 x 16
##    short_name has_kiosk external_id   lon   lat name  eightd_station_…
##    <chr>      <lgl>     <chr>       <dbl> <dbl> <chr> <list>          
##  1 6926.01    TRUE      66db237e-0… -74.0  40.8 W 52… <df[,0] [0 × 0]>
##  2 6926.01    TRUE      66db237e-0… -74.0  40.8 W 52… <df[,0] [0 × 0]>
##  3 5430.08    TRUE      66db269c-0… -74.0  40.7 Fran… <df[,0] [0 × 0]>
##  4 5430.08    TRUE      66db269c-0… -74.0  40.7 Fran… <df[,0] [0 × 0]>
##  5 5167.06    TRUE      66db277a-0… -74.0  40.7 St J… <df[,0] [0 × 0]>
##  6 5167.06    TRUE      66db277a-0… -74.0  40.7 St J… <df[,0] [0 × 0]>
##  7 4354.07    TRUE      66db281e-0… -74.0  40.7 Atla… <df[,0] [0 × 0]>
##  8 4354.07    TRUE      66db281e-0… -74.0  40.7 Atla… <df[,0] [0 × 0]>
##  9 6148.02    TRUE      66db28b5-0… -74.0  40.7 W 17… <df[,0] [0 × 0]>
## 10 6148.02    TRUE      66db28b5-0… -74.0  40.7 W 17… <df[,0] [0 × 0]>
## # … with 2,342 more rows, and 9 more variables: rental_url <chr>,
## #   station_id <chr>, electric_bike_surcharge_waiver <lgl>, region_id <chr>,
## #   legacy_id <chr>, capacity <int>, eightd_has_key_dispenser <lgl>,
## #   rental_methods <chr>, station_type <chr>